package com.example.chandao.common.easyexcel;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

public class JsonToExcelExporter {

    public static void main(String[] args) {
        String jsonData = "{\n" +
                "    \"code\": 200,\n" +
                "    \"msg\": \"操作成功\",\n" +
                "    \"data\": {\n" +
                "        \"EDC受试者数据下载-Java开发\": {\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 454,\n" +
                "                    \"productName\": \"EDC受试者数据下载-Java开发\",\n" +
                "                    \"count\": 22,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"小程序-开发\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 3,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 19,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 6,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 191,\n" +
                "                    \"productName\": \"小程序-开发\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"01 EDC-里恩临床试验电子数据采集系统\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 30,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 61,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 17,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 7,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"changed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 10,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 411,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 23,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 5,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"done\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 59,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 5,\n" +
                "                    \"productName\": \"01 EDC-里恩临床试验电子数据采集系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"pause\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"用户跟踪问题CAPA记录\": {\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 65,\n" +
                "                    \"productName\": \"用户跟踪问题CAPA记录\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"pause\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 65,\n" +
                "                    \"productName\": \"用户跟踪问题CAPA记录\",\n" +
                "                    \"count\": 59,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 65,\n" +
                "                    \"productName\": \"用户跟踪问题CAPA记录\",\n" +
                "                    \"count\": 5,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"done\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"05 SCTMS系统-陕西省人民医院\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 3,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 51,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 5,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 105,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 4,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 452,\n" +
                "                    \"productName\": \"05 SCTMS系统-陕西省人民医院\",\n" +
                "                    \"count\": 48,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"08 eTMF-里恩医学电子文档管理系统\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 152,\n" +
                "                    \"productName\": \"08 eTMF-里恩医学电子文档管理系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 152,\n" +
                "                    \"productName\": \"08 eTMF-里恩医学电子文档管理系统\",\n" +
                "                    \"count\": 6,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 152,\n" +
                "                    \"productName\": \"08 eTMF-里恩医学电子文档管理系统\",\n" +
                "                    \"count\": 4,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 152,\n" +
                "                    \"productName\": \"08 eTMF-里恩医学电子文档管理系统\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 152,\n" +
                "                    \"productName\": \"08 eTMF-里恩医学电子文档管理系统\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"05  SCTMS系统-右安门医院\": {\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 455,\n" +
                "                    \"productName\": \"05  SCTMS系统-右安门医院\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 455,\n" +
                "                    \"productName\": \"05  SCTMS系统-右安门医院\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"04 CTMS-临床研究管理系统\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"changed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 4,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 34,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 33,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 4,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 32,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 166,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 6,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"done\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"wait\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"pause\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"doing\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 158,\n" +
                "                    \"productName\": \"04 CTMS-临床研究管理系统\",\n" +
                "                    \"count\": 53,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"07 里恩eLearning-在线培训系统\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 42,\n" +
                "                    \"productName\": \"07 里恩eLearning-在线培训系统\",\n" +
                "                    \"count\": 7,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 42,\n" +
                "                    \"productName\": \"07 里恩eLearning-在线培训系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 42,\n" +
                "                    \"productName\": \"07 里恩eLearning-在线培训系统\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 42,\n" +
                "                    \"productName\": \"07 里恩eLearning-在线培训系统\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 42,\n" +
                "                    \"productName\": \"07 里恩eLearning-在线培训系统\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"四价肠道病毒灭活疫苗（Vero细胞）Ⅰ期、Ⅱ期及长效安全性观察\": {\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 456,\n" +
                "                    \"productName\": \"四价肠道病毒灭活疫苗（Vero细胞）Ⅰ期、Ⅱ期及长效安全性观察\",\n" +
                "                    \"count\": 97,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"05 SCTMS系统-西安大兴医院\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"changed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 14,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 25,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 24,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 87,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 259,\n" +
                "                    \"productName\": \"05 SCTMS系统-西安大兴医院\",\n" +
                "                    \"count\": 20,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"05 SCTMS系统-延安大学咸阳医院\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 6,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 28,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 49,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 5,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 453,\n" +
                "                    \"productName\": \"05 SCTMS系统-延安大学咸阳医院\",\n" +
                "                    \"count\": 30,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"03 PV-药物警戒系统\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 11,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 11,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 17,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 129,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 18,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 6,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 15,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 151,\n" +
                "                    \"productName\": \"03 PV-药物警戒系统\",\n" +
                "                    \"count\": 12,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"done\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"10 Link-临链平台\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 459,\n" +
                "                    \"productName\": \"10 Link-临链平台\",\n" +
                "                    \"count\": 7,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"09 ePro 电子患者报告临床结局系统\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 21,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 9,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 31,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 127,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 24,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 4,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 286,\n" +
                "                    \"productName\": \"09 ePro 电子患者报告临床结局系统\",\n" +
                "                    \"count\": 45,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"IIT研究数字化平台\": {\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 321,\n" +
                "                    \"productName\": \"IIT研究数字化平台\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"resolved\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"任务\": [\n" +
                "                {\n" +
                "                    \"productId\": 321,\n" +
                "                    \"productName\": \"IIT研究数字化平台\",\n" +
                "                    \"count\": 5,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"done\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 321,\n" +
                "                    \"productName\": \"IIT研究数字化平台\",\n" +
                "                    \"count\": 59,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"closed\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 321,\n" +
                "                    \"productName\": \"IIT研究数字化平台\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"任务\",\n" +
                "                    \"status\": \"pause\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        },\n" +
                "        \"韧致CTMS\": {\n" +
                "            \"需求\": [\n" +
                "                {\n" +
                "                    \"productId\": 449,\n" +
                "                    \"productName\": \"韧致CTMS\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                },\n" +
                "                {\n" +
                "                    \"productId\": 449,\n" +
                "                    \"productName\": \"韧致CTMS\",\n" +
                "                    \"count\": 2,\n" +
                "                    \"type\": \"需求\",\n" +
                "                    \"status\": \"draft\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"bug\": [\n" +
                "                {\n" +
                "                    \"productId\": 449,\n" +
                "                    \"productName\": \"韧致CTMS\",\n" +
                "                    \"count\": 1,\n" +
                "                    \"type\": \"bug\",\n" +
                "                    \"status\": \"active\",\n" +
                "                    \"startTime\": null,\n" +
                "                    \"endTime\": null\n" +
                "                }\n" +
                "            ]\n" +
                "        }\n" +
                "    }\n" +
                "}";


        try {
            exportToExcel(jsonData, "产品统计数据.xlsx");
            System.out.println("Excel 导出成功！");
        } catch (IOException e) {
            System.err.println("导出失败: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void exportToExcel(String jsonData, String filePath) throws IOException {
        // 解析 JSON 数据
        JSONObject root = new JSONObject(jsonData);
        JSONObject productsData = root.getJSONObject("data");

        // 创建工作簿和工作表
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("产品统计");

        // 存储所有列名（动态生成）
        Set<String> allColumns = new LinkedHashSet<>();
        allColumns.add("产品名称");

        // 处理每个产品的数据
        List<Map<String, Object>> productList = new ArrayList<>();
        for (String productName : productsData.keySet()) {
            JSONObject productInfo = productsData.getJSONObject(productName);
            Map<String, Object> productRow = new LinkedHashMap<>();
            productRow.put("产品名称", productName);

            // 处理需求数据
            processItemType(productInfo, "需求", productRow, allColumns);
            // 处理 bug 数据
            processItemType(productInfo, "bug", productRow, allColumns);
            // 处理任务数据
            processItemType(productInfo, "任务", productRow, allColumns);

            productList.add(productRow);
        }

        // 创建表头
        Row headerRow = sheet.createRow(0);
        List<String> columnNames = new ArrayList<>(allColumns);
        for (int i = 0; i < columnNames.size(); i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(columnNames.get(i));
        }

        // 填充数据
        for (int rowIndex = 0; rowIndex < productList.size(); rowIndex++) {
            Map<String, Object> rowData = productList.get(rowIndex);
            Row dataRow = sheet.createRow(rowIndex + 1);

            for (int colIndex = 0; colIndex < columnNames.size(); colIndex++) {
                String columnName = columnNames.get(colIndex);
                Cell cell = dataRow.createCell(colIndex);

                Object value = rowData.get(columnName);
                if (value instanceof Integer) {
                    cell.setCellValue((Integer) value);
                } else if (value instanceof String) {
                    cell.setCellValue((String) value);
                } else {
                    cell.setCellValue("");
                }
            }
        }

        // 自动调整列宽
        for (int i = 0; i < columnNames.size(); i++) {
            sheet.autoSizeColumn(i);
        }

        // 保存 Excel 文件
        try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
            workbook.write(fileOut);
        } finally {
            workbook.close();
        }
    }

    private static void processItemType(JSONObject productInfo, String itemType,
                                        Map<String, Object> productRow, Set<String> allColumns) {
        if (productInfo.has(itemType)) {
            JSONArray items = productInfo.getJSONArray(itemType);
            Map<String, Integer> statusCount = new HashMap<>();

            // 统计每种状态的数量
            for (Object itemObj : items) {
                JSONObject item = (JSONObject) itemObj;
                String status = item.getString("status");
                int count = item.getInt("count");
                statusCount.put(status, statusCount.getOrDefault(status, 0) + count);
            }

            // 添加到产品行数据
            int total = 0;
            for (Map.Entry<String, Integer> entry : statusCount.entrySet()) {
                String columnName = itemType + "_" + entry.getKey();
                productRow.put(columnName, entry.getValue());
                allColumns.add(columnName);
                total += entry.getValue();
            }

            // 添加总数列
            String totalColumnName = itemType + "总数";
            productRow.put(totalColumnName, total);
            allColumns.add(totalColumnName);
        }
    }
}